home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / Bounce.bproj / Bounce.m < prev    next >
Encoding:
Text File  |  1995-02-04  |  5.2 KB  |  222 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    Bounce.m
  3. //    SUMMARY:    Implementation of Bouncy annotations to eText documents
  4. //    SUPERCLASS:    Object
  5. //    INTERFACE:    None
  6. //    PROTOCOLS:    <DocNotification, Annotation, Tool>
  7. //    AUTHOR:        Rohit Khare
  8. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  9. ///////////////////////////////////////////////////////////////////////////////
  10. //    DESCRIPTION
  11. //        Glue for Ali Ozer's LinesView code. Demo of <Annotation>
  12. ///////////////////////////////////////////////////////////////////////////////
  13. //    HISTORY
  14. //    10/31/94:    Converted to eText5.0 inspector protocol.
  15. //    02/04/94:    Created. Derived from NextDeveloper/Examples/Appkit/Lines.
  16. ///////////////////////////////////////////////////////////////////////////////
  17.  
  18. #import "Bounce.h"
  19.  
  20. @implementation Bounce
  21. + toolAwake:theApp
  22. {
  23.     char        buf[MAXPATHLEN];
  24.     NXBundle    *bundle;
  25.     NXImage        *theIcon;
  26.  
  27.     bundle = [NXBundle bundleForClass:[Bounce class]];
  28.     if ( [bundle getPath:buf forResource:"BounceIcon" ofType:"tiff"] ) {
  29.         theIcon = [[NXImage alloc] initFromFile:buf];
  30.     } else {
  31.         NXLogError("Image not found: BounceIcon");
  32.         theIcon = [NXImage findImageNamed:"NXdefaulticon"];
  33.     }
  34.     [theApp   registerAnnotation: [Bounce class] 
  35.                             name: "Bounce"
  36.                     RTFDirective: "Bounce"
  37.                        menuLabel: "Fun Stuff/Insert Bouncy..."
  38.                          menuKey: '\0'
  39.                         menuIcon: (NXImage *) theIcon];
  40.     return self;
  41. }
  42.  
  43. -init 
  44. {
  45.     char        buf[MAXPATHLEN];
  46.     NXBundle   *bundle;
  47.     NXRect        frame;
  48.  
  49.     [super init];
  50.     bundle = [NXBundle bundleForClass:[Bounce class]];
  51.     if ( [bundle getPath:buf forResource:"Bounce" ofType:"nib"] ) {
  52.         [NXApp loadNibFile:buf owner:self withNames:NO];
  53.     } else {
  54.         NXLogError("NIB not found: Bounce");
  55.     }
  56.     controlView = [controlPanel contentView];
  57.     frame.origin.x = frame.origin.y = 0.0;
  58.     frame.size.width = frame.size.height = 48.0;
  59.     sz.width = sz.height = 48.0;
  60.     corners = 5;
  61.     linesView = [[LinesView alloc] initFrame:&frame];
  62.     [linesView setNumberOfCorners:self];
  63.     return self;
  64. }
  65. - initFromPboard:thePboard inDoc:theDoc linked:(BOOL) linked
  66. {
  67.     [self init];
  68.     return self;
  69. }
  70.  
  71. - free {
  72.     [[NXApp inspector] invalidate];
  73.     etDoc=nil;
  74.     [linesView off];
  75.     [linesView removeFromSuperview];
  76.     [NXApp delayedFree:linesView];
  77.     [controlPanel free];
  78.     return [super free];
  79. }
  80.  
  81. - (int)intValue {return corners;}
  82.  
  83. - readRichText:(NXStream *)stream forView:view 
  84. {
  85.     NXScanf(stream, "%f %f %d", &sz.height, &sz.width, &corners);
  86.     [linesView setNumberOfCorners:self];
  87.     return self;
  88. }
  89.  
  90. - writeRichText:(NXStream *)stream forView:view
  91. {
  92.     NXPrintf(stream, "%f %f %d", sz.height, sz.width, corners);
  93.     return self;
  94. }
  95.  
  96. - calcCellSize:(NXSize *)theSize
  97. {
  98.     theSize->width = sz.width;
  99.     theSize->height = sz.height;
  100.     return self;
  101. }
  102. - highlight:(const NXRect *)cellFrame inView:controlView lit:(BOOL)flag
  103. {
  104.       static BOOL highlighted=NO;
  105.     if (highlighted != flag) {
  106.         highlighted = flag;
  107.         
  108.         /* toggle highlighting */
  109.             NXHighlightRect(cellFrame);
  110.         
  111.         /* make change visible */
  112.         //[[cView window] flushWindow];
  113.     }
  114.     
  115.     return self;
  116. }
  117. - drawSelf:(const NXRect *)cellFrame inView:cView
  118. {
  119.     
  120.     PSgsave();
  121.     if ([linesView superview] == NULL)
  122.         [cView addSubview:linesView];
  123.     // To show a view, we do a move/display combination
  124.     [linesView moveTo:cellFrame->origin.x :cellFrame->origin.y];
  125.     [linesView sizeTo:sz.width :sz.height];
  126.     PSgrestore();
  127.     [linesView display];
  128.     return self;
  129. }
  130.  
  131. - (BOOL)     trackMouse:(NXEvent *)event
  132.             inRect:(const NXRect *)cellFrame
  133.             ofView:cView
  134. {
  135.     NXPoint mouseLocation;
  136.     
  137.     mouseLocation = event->location;
  138.     [cView convertPoint:&mouseLocation fromView:NULL];
  139.  
  140.     if (NXPointInRect(&mouseLocation, cellFrame))
  141.         if (event->data.mouse.click == 2)
  142.             [self doubleClick:self];
  143.         else if (event->data.mouse.click == 1)
  144.          {
  145.             [[NXApp inspector] inspect: self];
  146.             if (!(event->flags && NX_COMMANDMASK))
  147.                 [self click:self];
  148.         }
  149.     return YES;
  150. }
  151.  
  152. - click:sender
  153. {
  154.     sz.width = [widthField floatValue];
  155.     sz.height = [heightField floatValue];
  156.     corners = [cornerField intValue];
  157.     [linesView setNumberOfCorners:self];
  158.     [linesView toggleRun:sender];
  159.     return self;
  160. }
  161. - doubleClick:sender
  162. {
  163.     return self;
  164. }
  165.  
  166.  
  167. - editCorners:sender
  168. {
  169.     corners = [cornerField intValue];
  170.     return [linesView setNumberOfCorners:self];
  171. }
  172.  
  173. - editSize:sender
  174. {
  175.     sz.width = [widthField floatValue];
  176.     sz.height = [heightField floatValue];
  177.     return self;
  178. }
  179.  
  180.  
  181.  
  182. - (const NXAtom *) types
  183. {
  184.     static NXAtom types[2] = {NULL, NULL};
  185.     
  186.     if (!types[0]) {
  187.         types[0] = NXUniqueString("Controls");
  188.     }
  189.     return types;
  190. }
  191.  
  192. - (const char *) inspectorTitle
  193. {
  194.     return  NXUniqueString("Bouncing Lines");
  195. }
  196.  
  197. - resignInspector: (View *) oldInspector ofType: (const char *) type 
  198. {
  199.     sz.width = [widthField floatValue];
  200.     sz.height = [heightField floatValue];
  201.     corners = [cornerField intValue];
  202.     [linesView setNumberOfCorners:self];
  203.     return self;
  204. }
  205.  
  206. - activateInspector: (View *) newInspector ofType: (const char *) type 
  207. {
  208.     [widthField setFloatValue:sz.width];
  209.     [heightField setFloatValue:sz.height];
  210.     [cornerField setIntValue:corners];
  211.     return self;
  212. }
  213.  
  214. - inspectorForType:(const char *) type 
  215. {
  216.     if(!strcmp(type,NXUniqueString("Controls")))
  217.         return controlView;
  218.     else NXLogError("Massive Inspector Failure: Asked Bouncy for: %s", type);
  219.     return controlView;
  220. }
  221.  
  222. @end